package com.ayoka.base;

import java.lang.ref.WeakReference;

/**
 * =========================================================
 * @ProjectName:
 * @ClassName: BasePresenter
 * @Description:
 * @Author: jincp
 * @CreateDate: 2019/3/14 13:55
 * =========================================================
 */
public abstract class BasePresenter<V extends IBaseView> {

    protected static String TAG;

    protected WeakReference<V> mViewRef;

    public void attach(V view) {
        TAG = getClass().getSimpleName();
        mViewRef = new WeakReference<>(view);
    }

    public boolean isAttached() {
        return mViewRef != null && mViewRef.get() != null;
    }

    public void detachView() {
        if (isAttached()) {
            mViewRef.clear();
            mViewRef = null;
        }
    }
}